package com.anti_poverty_detection_system.springboot.service.impl;

import com.anti_poverty_detection_system.springboot.mapper.UsersMapper;
import com.anti_poverty_detection_system.springboot.model.Users;
import com.anti_poverty_detection_system.springboot.service.IUsersService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import jakarta.transaction.Transactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ZITONG BAI
 * @since 2024-06-17
 */
@Service
public class UsersServiceImpl extends ServiceImpl<UsersMapper, Users> implements IUsersService {

    @Autowired
    private UsersMapper usersMapper;


    @Override
    public Users getUserByUsername(String username){
        QueryWrapper<Users> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("username",username);
        return usersMapper.selectOne(queryWrapper);
    }
    @Override
    public Users getUserByUserId(Integer userId){
        QueryWrapper<Users> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("user_id",userId);
        return usersMapper.selectOne(queryWrapper);
    }
    @Override
    public Page<Users> getUsers(Page<Users> page){
        return usersMapper.selectPage(page,null);
    }
    @Override
    public Page<Users> getSearchUsers(Page<Users> page,Users users){
        return usersMapper.selectUsersPage(page,users);
    }
    @Override
    public boolean deleteUserByUsername(String username){
        QueryWrapper<Users> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("username",username);
        usersMapper.delete(queryWrapper);
        return true;
    }
}
